# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pycairo

pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-python3-cairo-git"
provides=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
pkgver=1.10.1.34.5a45b0b
pkgrel=1
pkgdesc="Python 3 bindings for the cairo graphics library (mingw-w64)"
url="http://www.cairographics.org/pycairo"
arch=('any')
license=('LGPL' 'MPL')
depends=("${MINGW_PACKAGE_PREFIX}-python3" "${MINGW_PACKAGE_PREFIX}-cairo")
makedepends=('git')
source=("git://git.cairographics.org/git/pycairo"
        0001-msys2-port-to-subprocess.check_output.patch
        0003-fix-PyVarObject_HEAD_INIT-problem.patch)
sha256sums=('SKIP'
            'bbd943874a097353dcbbadc2d40b49772f6c8e514889d55f8a56935a20215fe2'
            '0ac9a474266a5cb84692014c82707332571680c4f4d16531c6eaed1e0d1d5751')

pkgver() {
  cd $_realname
  PREFIX="pycairo_version        = '"
  ver=$(grep "$PREFIX" setup.py | sed "s/$PREFIX//" | sed "s/'//")
  revision=$(git rev-list --count HEAD)
  hash=$(git log --pretty=format:'%h' -n 1)
  echo $ver.$revision.$hash
}

prepare() {
  cd ${_realname}
  git am ${srcdir}/0001-msys2-port-to-subprocess.check_output.patch
  git am ${srcdir}/0003-fix-PyVarObject_HEAD_INIT-problem.patch
}

build() {
  cd $_realname
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {
  cd $_realname
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py --prefix=${MINGW_PREFIX} --root="$pkgdir" install --root=$pkgdir/
}
